import java.io.*;

public class Task {

    public static void main(String[] args) throws IOException {
        // 复制文件
        String rootPath = "lesson9/task4/";
        
        // 将lesson9/task4/resource/meizi.jpg复制到lesson9/task4/resource/meinv.jpg
        copyFile(rootPath);

        System.out.println("复制完成");
    }

    public static void copyFile(String rootPath) throws IOException {
        // 1. 创建源
        InputStream is = new FileInputStream(rootPath + "resource/meizi.jpg");
        // 2. 创建文件输出流
        OutputStream os = new FileOutputStream(rootPath + "resource/meinv.jpg");

        // 3. 创建buffer
        byte[] buffer = new byte[1024];
        int len = -1;
        // 4. 读取文件
        while ((len = is.read(buffer)) != -1) {
            // 5. 写入文件
            os.write(buffer, 0, len);
        }
        // 6. 关闭流
        os.close();
        is.close();
    }

}